package com.lh.project.controller;

import com.lh.project.common.BaseResponse;
import com.lh.project.common.ResultUtils;
import com.lh.project.model.entity.Food;
import com.lh.project.service.FoodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

import static com.lh.project.common.ErrorCode.NOT_FOUND_ERROR;

@RestController
@RequestMapping("/food")
@Slf4j
public class FoodController {
    @Resource
    private FoodService foodService;

    /**
     * 根据分类id获取餐品
     *
     * @param id
     * @return
     */
    @GetMapping("/getList")
    public BaseResponse<List<Food>> getFoodList(@RequestParam long id,@RequestParam int current) {
        //没有整合redis
        List<Food> foods = foodService.queryFoodList(id, current);
        //盛和了redis
//        List<Food> foods = foodService.queryFoodListByRedis(id,current);
        return  ResultUtils.success(foods);
    }

    /**
     * 获取餐品的详细信息
     * @param id
     * @return
     */
    @GetMapping("/get")
    public BaseResponse<Food> getFoodById(@RequestParam long id){
        Food food = foodService.myGetById(id);
        //没有整合redis之前
//        Food food = foodService.getById(id);
        return food!=null? ResultUtils.success(food):ResultUtils.error(NOT_FOUND_ERROR);
    }
}
